// 入口函数
$(document).ready(function () {

    let len = $("select[name='choose']").find("option").length;

    //加载药品消息
    if (len === 0) {
        // 把药品编号和类型绑定到选择框
        $.ajax({
            url: "/drug/drugs",
            type: "post",
            dataType: "json",
            success: function (data) {
                $.each(data, function (index, val) {
                    let id = val.id;
                    let drug = val.drugName;
                    let option = "<option value= '" + id + "'>" + drug + "</option>";
                    $("select[name='choose']").append(option);
                });
                //加载表单
                layui.use('form', function () {
                    let form = layui.form;
                    form.render('select', 'test1');
                });
            }
        })
    }

    //检查库存部分
    $("body").on('click', '.kun .liui .check', function () {
        let flag = $(this).is(":checked");
        if (flag) {
            $("body .kun .liuis .check").each(function () {
                $(this)[0].checked = true;
            })
        } else {
            $("body .kun .liuis .check").each(function () {
                $(this)[0].checked = false;
            })
        }
    })

})
